'''
Module containing class that is used for user management.
'''


from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
#from maps import Event
# Create your models here.

class UserProfile(models.Model):
    'This class extends django\'s standard models.Model'
    'Used as user representation in mapa-imprez system'
    
    
    ROLE_TYPE = (
        ('O', 'Ordinary'),
        ('C', 'Corporation'),
        ('A', 'Admin')
    )
    'Types of possible roles'
    
    user = models.OneToOneField(User)
    'Instance of standard auth.models.User object representing standard user info'
    
    
    fullname = models.CharField(max_length=255, default='')
    'Name describing this entity (important for institutions and companies)'
    
    
    role = models.CharField(max_length=1, choices=ROLE_TYPE, default='O')
    'Field that keeps information on user\'s role in the system'
    
    accepted = models.BooleanField(default=False)
    'Information on whether this user has been accepted by administrator as an institution'
    
    def getEvents(self):
        'Returning all events created by the user'
        return self.events.all()
    
    def __unicode__(self):
        'String representation of UserProfile object'
        return '%s %s' % (self.user.username, self.user.email)


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)